#include <iostream>
#include <unistd.h>
#include <netdb.h>
#include <map>
#include <pthread.h>
#include <string>
#include <sys/socket.h>
#include <string.h>
#include <cstdlib>
#include <set>
#include <vector>
#include <utility>   //pair

#define PORT 8080
#define MAX 256
#define MAX_CLIENT 10

using namespace std;
class User;
class Post;
extern map<string,string> passwd;
extern map<string,User> alluser;  //用户名类和字符串映射
extern int sockfd,t;
extern vector<Post> postmsg;
void ConnectClient(struct sockaddr_in servaddr);
bool isuser(string s);
bool ispasswd(string name,string newpasswd);
void adduser(string name,string newpasswd);
string dealdata(int connfd);
string DealLogin(int connfd);
void sentmessage(int connfd,string user,string myfriend);
void dealchat(int connfd,string user);
bool inalluser(string myfriend);
void sentpost(int connfd);
void seedetail(int connfd,string s);
void dealpost(int connfd,string user);

class User{
public:  

User();
bool isfriend(string myfriend);
string getfriend();
void addfriend(string myfriend);
void addmessage(string myfriend,pair<string,string> amsg);
void sent(int connfd,string myfriend);
void getmsg(int connfd);
void clean(string myfriend);
int getmsgnum();
private:
map<string,map<string,string>>  mymessage;
set<string> allfriends;
};

class Post{
public:
Post();
Post(const string& user,const string& title,const string& time,const string& data);
void addpost(string user,string time,string title,string data);
string getpuser();
string getptime();
string getptitle();
string getpdata();
private:
string puser;
string ptime;
string ptitle;
string pdata;
};
